#include "show_info.h"
#include "table.h"
#include "node.h"
void print_excute()
{
    printf("Executed.\n");
}

void print_prompt()
{
    printf("db > ");
}

void print_constants()
{
    printf("ROW_SIZE: %d\n", ROW_SIZE);
    printf("COMMON_NODE_HEADER_SIZE: %d\n", COMMON_NODE_HEADER_SIZE);
    printf("LEAF_NODE_HEADER_SIZE: %d\n", LEAF_NODE_HEADER_SIZE);
    printf("LEAF_NODE_CELL_SIZE: %d\n", LEAF_NODE_CELL_SIZE);
    printf("LEAF_NODE_SPACE_FOR_CELLS: %d\n", LEAF_NODE_SPACE_FOR_CELLS);
    printf("LEAF_NODE_MAX_CELLS: %d\n", LEAF_NODE_MAX_CELLS);
}

// 打印level个空格
void indent(uint32_t level)
{
    for (int i = 0; i < level; i++)
    {
        printf("  ");
    }
};
// 打印树，先序遍历
void print_tree(Pager *pager, uint32_t page_num, uint32_t indentation_level)
{
    switch (get_node_type(get_page(pager, page_num)))
    {
    case NODE_LEAF:
        // 叶节点
        Node *node = (Node *)get_page(pager, page_num);
        indent(indentation_level);
        printf("- leaf (size %d)\n", node->num_cells);
        for (int i = 0; i < node->num_cells; i++)
        {
            indent(indentation_level + 1);
            printf("- %d\n", node->rows[i].key);
        }
        break;
    case NODE_INTERNAL:
        // 内部节点
        Internal_Node *internal_node = (Internal_Node *)get_page(pager, page_num);
        indent(indentation_level);
        printf("- internal (size %d)\n", internal_node->num_keys);
        for (int i = 0; i <= internal_node->num_keys; i++)
        {
            uint32_t child_page = internal_node->internal_leaf[i].child_page;
            print_tree(pager, child_page, indentation_level + 1);
            indent(indentation_level + 1);
            printf("- key %d\n", internal_node->internal_leaf[i].key);
        }
        break;
    default:
        break;
    }
};